package com.ruoyi.bizsys.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.VerifyCodeLog;
import com.ruoyi.bizsys.service.IVerifyCodeLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验证码记录Controller
 *
 * @author african-loan
 * @date 2021-01-14
 */
@RestController
@RequestMapping("/business/verify_code_log")
public class VerifyCodeLogController extends BaseController {
    @Autowired
    private IVerifyCodeLogService verifyCodeLogService;

    /**
     * 查询验证码记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:list')")
    @GetMapping("/list")
    public TableDataInfo list(VerifyCodeLog verifyCodeLog) {
        startPage();
        List<VerifyCodeLog> list = verifyCodeLogService.selectVerifyCodeLogList(verifyCodeLog);
        return getDataTable(list);
    }

    /**
     * 导出验证码记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:export')")
    @Log(title = "验证码记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VerifyCodeLog verifyCodeLog) {
        List<VerifyCodeLog> list = verifyCodeLogService.selectVerifyCodeLogList(verifyCodeLog);
        ExcelUtil<VerifyCodeLog> util = new ExcelUtil<VerifyCodeLog>(VerifyCodeLog.class);
        return util.exportExcel(list, "verify_code_log");
    }

    /**
     * 获取验证码记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(verifyCodeLogService.selectVerifyCodeLogById(id));
    }

    /**
     * 新增验证码记录
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:add')")
    @Log(title = "验证码记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VerifyCodeLog verifyCodeLog) {
        return toAjax(verifyCodeLogService.insertVerifyCodeLog(verifyCodeLog));
    }

    /**
     * 修改验证码记录
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:edit')")
    @Log(title = "验证码记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VerifyCodeLog verifyCodeLog) {
        return toAjax(verifyCodeLogService.updateVerifyCodeLog(verifyCodeLog));
    }

    /**
     * 删除验证码记录
     */
    @PreAuthorize("@ss.hasPermi('business:verify_code_log:remove')")
    @Log(title = "验证码记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(verifyCodeLogService.deleteVerifyCodeLogByIds(ids));
    }
}
